package com.cloud.auth.service.impl;

import com.cloud.auth.mapper.BaseMapper;
import com.cloud.auth.service.BaseService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @packageName: com.api.service
 * @name: BaseServiceImpl
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/6/12 16:04
 */
public abstract class BaseServiceImpl implements BaseService {

    protected abstract BaseMapper getMapper();

    /**
     * 添加数据
     *
     * @param map
     * @return
     */
    @Override
    @Transactional
    public int add(Map<String, Object> map) {
        return this.getMapper().insert(map);
    }

    /**
     * 批量添加
     *
     * @param list
     * @return
     */
    @Override
    @Transactional
    public int addBatch(List<Map<String, Object>> list) {
        return this.getMapper().insertBatch(list);
    }

    /**
     * 更新数据
     *
     * @param map
     * @return
     */
    @Override
    @Transactional
    public int update(Map<String, Object> map) {
        return this.getMapper().update(map);
    }

    /**
     * 删除数据
     *
     * @param map
     * @return
     */
    @Override
    @Transactional
    public int del(Map<String, Object> map) {
        return this.getMapper().delete(map);
    }

    /**
     * 获取单条数据
     *
     * @param map
     * @return
     */
    @Override
    public Map<String, Object> get(Map<String, Object> map) {
        return this.getMapper().get(map);
    }

    /**
     * 下拉列表
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> simpleList(Map<String, Object> map) {
        return this.getMapper().simpleList(map);
    }

    /**
     * 分页列表
     *
     * @param map
     * @param pageSize
     * @param pageNo
     * @return
     */
    @Override
    public List<Map<String, Object>> pagination(Map<String, Object> map, int pageSize, int pageNo) {
        map.put("start", (pageNo - 1) * pageSize);
        map.put("num", pageSize);
        return this.getMapper().list(map);
    }

    /**
     * 分页数据统计条数
     *
     * @param map
     * @return
     */
    @Override
    public long count(Map<String, Object> map) {
        return this.getMapper().count(map);
    }
}
